package test;

/**
 * @author dx
 * @version 1.0
 * @date 2022/5/23 12:54
 * @description: 剑指offer 54 二叉搜索树的第K大节点
 */
public class Knode {
}


class Knode_Solution{
    int i = 1;
    int ans = -1;
    public int kthLargest(TreeNode root, int k){
        inorder(root,k);
        return ans;
    }
    public void inorder(TreeNode root,int k){
        if(root == null){
            return;
        }
        inorder(root.right,k);
        if(i == k){
            ans = root.val;
        }
        i++;
        inorder(root.left,k);
    }
}